// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App'
import router from './router'
import axios from 'axios'
import VueAxios from 'vue-axios'
import qs from 'qs'
import VueElementLoading  from 'vue-element-loading'
import $ from 'jquery'

import VueWechatTitle from 'vue-wechat-title'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'

Vue.use(VXETable)
Vue.use(VueWechatTitle)

Vue.config.productionTip = false
Vue.use(ElementUI);
Vue.use(VueAxios,axios);
Vue.prototype.$qs = qs;
axios.defaults.baseURL = '/api';
const components = {
  VueElementLoading
};



// router.beforeEach((to, from, next) => {
//   if(to.meta.needLogin){
//     console.log(12316546,window.sessionStorage.data);
//     if(window.sessionStorage.data){
//       next();
//     }else{
//       next("/");
//     }
//   }else{
//     next();
//   }
// }),


router.beforeEach((to, from, next) => {
  if (to.matched.some(record => record.meta.requiresAuth)) {
      if (!window.sessionStorage.data) { 
          next({
              path: '/Login',
              query: { redirect: to.fullPath }
          })
      } else {
          next()
      }
  } else {
      next()
  }
})


router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  const type = to.meta.type
  // 判断该路由是否需要登录权限
  if (type === 'login') {
    if (window.localStorage.getItem('userMess')) {
      next()
    } else {
      next('/')
    }
  } else {
    next()  // 确保一定要有next()被调用
  }
})

// router.beforeEach((to, from, next) => {
//   if (to.matched.some(record => record.meta.requiresAuth)) {
//     if (!window.sessionStorage.data) { 
//         next({
//             path: '/Login',
//             query: { redirect: to.fullPath }
//         })
//       } else {
//           next()
//       }
//   } else {
//       next()
//   }
//   if(to.meta.title) {
//     document.title = to.meta.title
//   }else{
//     next();
//   }

// })
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
  
})
